package com.example.btnapplication;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class Guidpage extends Activity {

	private ViewPager guidViewPager;
	private LinearLayout guidLinearLayout;
	private ArrayList<View> pointList = new ArrayList<View>();
	private int[] drawableids = new int[] { R.drawable.p_01, R.drawable.p_02,
			R.drawable.p_03, R.drawable.p_04, R.drawable.p_05, };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_guidpage);

		guidViewPager = (ViewPager) findViewById(R.id.guidViewPager);
		guidLinearLayout = (LinearLayout) findViewById(R.id.guidLinearLayout);
		initguidLinearLayout();
		
		GuidViewPagerAdapter adapter = getGuidViewPagerAdapter();
		guidViewPager.setAdapter(adapter);
		guidViewPager.setOnPageChangeListener(adapter);
	}

	private void initguidLinearLayout() {
		for (int i = 0; i < drawableids.length; i++) {
			View pointView = new View(this);
			LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(20,20);
			lp.setMargins(10, 0, 10, 0);
			pointView.setLayoutParams(lp);
			pointView.setBackgroundResource(R.drawable.bg_point);
			guidLinearLayout.addView(pointView);
			pointList.add(pointView);
		}
	}

	private GuidViewPagerAdapter getGuidViewPagerAdapter() {
		ArrayList<ImageView> mImageViewList = new ArrayList<ImageView>();
		for (int drawableid : drawableids) {
			ImageView iv = new ImageView(this);
			iv.setBackgroundResource(drawableid);
			mImageViewList.add(iv);
		}
		return new GuidViewPagerAdapter(mImageViewList,guidLinearLayout,pointList);
	}
}
